#ifndef NETWORK_H
#define NETWORK_H

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <strings.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdlib.h>
#include <net/if_arp.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <string.h>
#include <stdbool.h>
#include <pthread.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <dirent.h>
#include <errno.h>

#define     all_port  6666

#define raw_fifo_name "./Code.zip"   		//发送的文件名
#define recv_fifo_name "./recv_Code.zip"    //接收后的文件名

//清屏
#define CLEAR() printf("\033[2J")

// 上移光标
#define MOVEUP(x) printf("\033[%dA", (x))

// 下移光标
#define MOVEDOWN(x) printf("\033[%dB", (x))

//光标复位
#define M_ret()	printf("%c[0;0H", 0x1b)  /*把光标移动到(0,0)位置*/

int fd2;
int fd1;
char s_fifo_name[32];

int move_pp;			//总大小24

int move_status;			//总大小24

//UDP接收类型标志判断
enum 
{
	online_flag, 		//上线标志
	offline_flag, 		//下线标志
	msg_flag, 			//消息标志
	fifo_send, 			//文件发送标志
	fifo_recv,			//文件接收标志
	fifo_dir,			//文件夹
	fifo_no_dir			//文件

};

//TCP文件类型
struct fifo_data
{
			
			 char fifo_name[32];
			 char fifo_type[32];
			 char fifo_buff[1024];
	unsigned long long data_len;
						int ret;
};

struct msg_data
{
	int data_size;
	char name[16];
	struct fifo_data myfifo;
};

//好友链表
struct friend_list{
	
	char name[256];
	char sex[8];
	struct sockaddr_in addr;
	struct friend_list *next;
};

//TCP、UDP消息结构体
struct recv_info{
	
	char name[256];
	int msg_flag;
	int fifo_flag;
	int fifo_port;
	char fifo_name[32];
	char msg_buffer[4096];
};

struct fifo_list{
	
	char f_name[32];
	char f_type[4];
	struct fifo_list *next;
};

struct c_dir{
	
	char dir_name;
	struct fifo_list my_filo_name;
	
};

//自身链表
struct glob_info{
	
	char name[256];
	char sex[8];
	int skt_fd;	
	struct friend_list *list_head;
};


#define	list_for_each(head, pos)\
	for(pos=head->next; pos!=NULL; pos=pos->next)



//好友下线，链表删除好友节点
int delete_friend_offline(struct glob_info *ginfo, char *offline_name);

//好友上线，判断链表中是否存在 或增加该成员
int add_newfriend(struct glob_info *ginfo, struct friend_list *cache_node, char *recv_name);

//申请客户端信息链表的头节点
struct friend_list *request_friend_info_node(const struct friend_list *info);

void insert_friend_info_node_to_link_list(struct friend_list *head, struct friend_list *insert_node);

void *send_fifo_data(void *arg);

int send_fifo_init(struct recv_info *msg, struct sockaddr_in *dest_addr);

void *recv_fifo_data(void *arg);

void *recv_broadcast_msg(void *arg);

int recv_fifo_init(struct recv_info *recv_msg, struct friend_list *cache_node);

int broadcast_msg_data(int skt_fd, const void *msg, ssize_t msg_len);

int show_all_friend(struct glob_info *ginfo);

int chat_with_friend(struct glob_info *ginfo, struct recv_info *msg);

int show_systems_msg();

int show_frient_msg();

int show_frient_list();

int goto_scanf();

int my_readdir(char *dirname);

int clear_down();

int is_or_no_dir(char *buf);

void DeletS2(char *s1,const char *s2);



#endif // NETWORK_H